﻿using System;
using ContractManagementSystem.BusinessLogic;

[assembly: CLSCompliant(true)]
namespace ContractManagementSystem
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Session["Name"] = "Admin";
            if(Session["Name"]!=null)
            {
                var sessionUser = Session["Name"].ToString();
                Menu(sessionUser);
                var newMessage = MessageBusiness.FetchNumber(sessionUser);
                UserLiteral.Text = "<a href='ViewProfile.aspx'>" + Session["Name"] + "</a>";
                //MessageLiteral.Text = "<a href='ViewMessage.aspx'>" + newMessage + "</a>";
                MessageLiteral.Text = "<a>" + newMessage + "</a>";
            }
            else
            {
                Response.Redirect("LogOn.aspx");
            }
        }

        protected void Menu(string sessionUser)
        {
            string role = UserBusiness.FetchRoleByUserName(sessionUser);
            RoleLabel.Text = role;

            if (role.Equals("Admin"))
            {
                AdminPanel.Visible = true;
                ClientPanel.Visible = false;
                ConsultantPanel.Visible = false;
                ContractorPanel.Visible = false;
            }
            else if (role.Equals("Contractor"))
            {
                AdminPanel.Visible = false;
                ClientPanel.Visible = false;
                ConsultantPanel.Visible = false;
                ContractorPanel.Visible = true;
            }
            else if (role.Equals("LineManager"))
            {
                AdminPanel.Visible = false;
                ClientPanel.Visible = true;
                ConsultantPanel.Visible = false;
                ContractorPanel.Visible = false;
            }
            else if (role.Equals("Consultant"))
            {
                AdminPanel.Visible = false;
                ClientPanel.Visible = false;
                ConsultantPanel.Visible = true;
                ContractorPanel.Visible = false;
            }

        }

        protected void LogOffLinkButton_OnClick(object sender, EventArgs e)
        {
            Session.Remove("Name");
            Response.Redirect("LogOn.aspx");
        }
    }
}
